<template>
	<view class="content">
		<view class="left">
			<view class="tab" :class="onactive==item.id?'active':''" @click="getList(item.id,item.name)"
				v-for="(item,index) in list" :key="item.id">
				<view v-if="onactive==item.id" class="tab-blue">
				</view>
				{{item.name}}
			</view>
		</view>
		<view class="right" v-show="ShopList.length>=1">
			<div class="tabName">{{ontitle}}</div>
			<view class="right_item" v-for="item in ShopList" :key="item.id" @click="navto(item)">
				<image class="R_item_img" :src="item.pic_image" mode=""></image>
				<view class="R_content">
					<view class="">{{item.name}}</view>
					<view class="R_content_info">
						<view class="">{{item.trade_time_text?item.trade_time_text:'暂无营业时间'}}</view>
						<view class="">{{item.address}}</view>
					</view>
				</view>
			</view>

		</view>
		<view class="right" v-show="ShopList.length==0">
			<view class="none">
				<image class="none_img" src="../../static/home/none.png" mode=""></image>
				<view class="">暂未收入，敬请期待!</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getShopType,
		getShopBy,
	} from '../../utls/api.js'
	export default {
		data() {
			return {
				onactive: 1,
				ontitle: '',
				page: 1,
				page_num: 10,
				list: [],
				ShopList: [],
				total: 0,
			}
		},
		onLoad(e) {
			console.log(uni.getStorageSync('ShopDetail'))

			if (e.share_id) {
				uni.setStorageSync('share_id', e.share_id);
				console.log(e.share_id)
			}
		},
		onShow() {
			this.shoptype()

			console.log("12", this.onactive)
			if (uni.getStorageSync('info').is_vip == 1) {
				uni.showShareMenu({
					withShareTicket: true,
					menus: ['shareAppMessage', 'shareTimeline'] //开启转发好友和转发朋友圈按钮
				});
			} else {
				uni.hideShareMenu({
					hideShareItems: ['shareTimeline', 'shareMenu']
				})
			}
		},

		onShareAppMessage: function(e) { // 分享到微信
			// 更多参数配置，参考文档
			let path = getCurrentPages();
			let route = path[path.length - 1].route;
			console.log(route, this.share_id)
			return {
				title: '同城泉友',
				path: `/${route}?share_id=${uni.getStorageSync('info').share_id}`,
			}
		},

		onShareTimeline() { // 分享到朋友圈
			let path = getCurrentPages();
			let route = path[path.length - 1].route;
			return {
				title: '同城泉友',
				path: `/${route}?share_id=${uni.getStorageSync('info').share_id}`,
			}
		},
		onReachBottom() {
			console.log("加载");
			if (this.total >= this.ShopList.length) {
				this.page++;
				this.getShopList();
			} else {
				console.log("触底无效")
			}

		},
		methods: {
			shoptype() {
				getShopType().then(res => {
					console.log(res)
					this.list = res.data.data
					this.onactive = uni.getStorageSync('Divide_id') ? uni.getStorageSync('Divide_id') : this.list[
						0].id;
					this.ontitle = uni.getStorageSync('Divide_title') ? uni.getStorageSync('Divide_title') : this
						.list[
							0].name;
					this.getList(this.onactive, this.ontitle)
				})
			},
			getList(id, title) {
				this.onactive = id;
				this.ontitle = title
				uni.setStorageSync('Divide_id', id)
				uni.setStorageSync('Divide_title', title)
				this.page = 1;
				this.ShopList = [];
				this.total = 0;
				this.getShopList()
			},
			getShopList() {
				let data = {
					type_id: this.onactive,
					page: this.page,
					page_num: this.page_num,
				}
				getShopBy(data).then(res => {
					console.log("店铺", res)
					if (res.data.code == 1) {
						this.ShopList = [...this.ShopList, ...res.data.data.data];
						this.total = res.data.data.total;
					} else {
						console.log("接口错误或无数据")
					}
				})
			},
			navto(item) {
				uni.setStorageSync('ShopDetail', item);
				uni.navigateTo({
					url: '/pages/index/Shopdetail',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: row;

		.left {
			background-color: #f6f6f6;
			width: 25%;
			font-size: 24rpx;
			line-height: 24rpx;
			height: 100vh;
			overflow-y: scroll;
			position: fixed;
			left: 0;
			top: 0;
			bottom: 0;

			.tab {
				padding: 40rpx 5rpx;
				font-size: 30rpx;
				text-align: center;
				position: relative;
				color: #333;

				.tab-blue {
					height: 30rpx;
					line-height: 30rpx;
					width: 8rpx;
					background-color: #40aae2;
					position: absolute;
					top: 40rpx;
				}
			}
		}

		.right {
			margin: 0rpx 0rpx 20rpx 26%;
			width: 75%;
			height: 100vh;
			overflow-y: scroll;

			.tabName {
				color: #000;
				font-size: 30rpx;
				font-weight: 700;
				margin: 20rpx 20rpx;
			}

			.right_item {
				display: flex;
				flex-direction: row;
				border-bottom: 1rpx solid #f3f3f3;
				border-top: 1rpx solid #f3f3f3;
				padding-top: 30rpx;
				padding-bottom: 30rpx;
				margin-left: 10px;
				margin-right: 10px;

				.R_item_img {
					max-width: 180rpx;
					min-width: 150rpx;
					height: 150rpx;
					border-radius: 10rpx;
				}

				.R_content {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					padding: 0rpx 10rpx;
					overflow: hidden;

					>view {
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						font-size: 28rpx;

						>view {
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							color: #999;
							font-size: 22rpx;
						}
					}
				}
			}

			.none {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				height: 100vh;

				.none_img {
					width: 150rpx;
					height: 150rpx;
					margin-bottom: 20rpx;
				}
			}
		}
	}

	.active {
		color: #000 !important;
		font-size: 35rpx;
		font-weight: 700;
		background-color: white !important;
	}
</style>